home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / demos / 157 / gfa / listbox.lst < prev    next >
Encoding:
File List  |  1987-07-14  |  3.5 KB  |  123 lines

  1. '
  2. '                               LISTBOX
  3. '                             by Gary Wren
  4. '
  5. ' This routine will display a list, draw an appropriately sized box around it
  6. ' and allow the user to use the mouse to select an item.  Merge it with your
  7. ' own programs and use it insted of "input" commands.
  8. '
  9. ' Experiment with lists of varying sizes by changing Max_item% below (0-29).
  10. ' This routine uses option base 0, so the first item is item$(0).
  11. '
  12. ' WARNING: Turn the sound off to avoid a continous bell.
  13. ' *******************************
  14. ' Put these three lines where appropriate in your program
  15. Clr Column%,Ty%,Tx%,Mk%,Mx%,My%,Cancel
  16. Max_items%=18                          ! You may have up to 30 items
  17. Dim Item$(Max_items%+1)                ! Item$(x)=item in the list
  18. ' -------------
  19. ' This assigns letter names to the items so you can run the routine on its own.
  20. ' Fill Item$() with your own names in your program.
  21. Ch=97
  22. Repeat
  23.   Inc K
  24.   Item$(K)=Chr$(Ch)
  25.   Inc Ch
  26. Until K=Max_items%+1
  27. ' ---------------------
  28. Gosub Listbox                         ! Don't forget this in your program!
  29. Pause 200                             ! Delete these two lines
  30. Edit
  31. ' **********************************
  32. Procedure Listbox
  33.   ' ---------             display the list
  34.   K=1
  35.   X=30
  36.   Y=50
  37.   Deftext 1,0,0,6
  38.   Repeat
  39.     Text X-25,Y,K
  40.     Text X,Y,Item$(K)
  41.     Inc K
  42.     Add Y,10
  43.     If K=16
  44.       Y=50
  45.       Add X,150
  46.     Endif
  47.   Until K=Max_items%+2
  48.   ' -------------------    draw a box around it
  49.   Defline 1,4,0,0
  50.   If X>150
  51.     Box 1,40,X+125,194
  52.   Else
  53.     Box 1,40,X+125,((K-1)*10)+44
  54.   Endif
  55.   ' -------------------     draw a "Cancel" button
  56.   Box 400,100,470,115
  57.   Text 412,110,"Cancel"
  58.   ' -------------          get the mouse position
  59.   Do
  60.     Clr Col%,Ty%,Tx%,Mk%,Mx%,My%
  61.     Mx%=Mousex
  62.     My%=Mousey
  63.     Mk%=Mousek
  64.     If Mk%=1
  65.       Deftext 1,0,0,6
  66.       Text Oldtx%-25,Oldy,Oldty%
  67.       Text Oldtx%,Oldy,Item$(Oldty%)
  68.       If Mx%>400 And Mx%<470 And My%>100 And My%<115
  69.         Deftext 2,1,0,6
  70.         Text 412,110,"Cancel"
  71.         Deftext 1,0,0,6
  72.         Cancel=1
  73.       Endif
  74.     Endif
  75.     ' ----------------                determine the column and row selected
  76.     If Mx%<=X+124 And My%=>40 And My%<195
  77.       If Mx%<=155
  78.         Tx%=30
  79.         Column%=0
  80.       Endif
  81.       If Mx%>155 And Mx%<=329
  82.         Tx%=180
  83.         Column%=1
  84.       Endif
  85.       Ty%=(Int((My%-45)/10)+1)
  86.       Y=40+(Ty%*10)
  87.       If Column%=1 And Ty%>0 Then
  88.         Add Ty%,15
  89.       Endif
  90.       ' ----------------
  91.       If Ty%<Max_items%+2 And Ty%>0 And Ty%<>Oldty%
  92.         Graphmode 1
  93.         ' -----------                  display a deselected item in white
  94.         Deftext 1,0,0,6
  95.         Text Oldtx%-25,Oldy,Oldty%
  96.         Text Oldtx%,Oldy,Item$(Oldty%)
  97.         '
  98.         ' ---------                    display the selection in red
  99.         Deftext 2,1,0,6
  100.         Text Tx%-25,Y,Ty%
  101.         Text Tx%,Y,Item$(Ty%)
  102.         ' ----------
  103.         Oldty%=Ty%
  104.         Oldtx%=Tx%
  105.         Oldcol%=Column%
  106.         Oldy=Y
  107.       Endif
  108.     Endif
  109.     Exit If (Mk%=1 And Ty%<Max_items%+2 And Ty%>0) Or Cancel=1
  110.   Loop
  111.   ' ----------------------                  Display position and item selected
  112.   If Cancel=1
  113.     Goto Ret
  114.   Endif
  115.   Print At(50,2);String$(29," ")
  116.   Print At(50,3);String$(29," ")
  117.   Print At(50,2);"Row=";Ty%;";       Column x=";Tx%
  118.   Print At(50,3);"Mouse x=";Mx%;";  Mouse y=";My%
  119.   Print At(50,4);String$(29," ")
  120.   Print At(50,4);"Choice= ";Ty%;". ";Item$(Ty%)
  121.   Ret:
  122. Return
  123.